package modele.cases;

import java.util.Collection;
import java.util.TreeMap;

import modele.cases.interfaces.CaseAbstract;
import modele.cases.interfaces.CasesInterface;

public class Cases implements CasesInterface {

	private TreeMap<Integer, CaseAbstract> cases;
	private int maxX;
	private int maxY;

	public Cases(int maxX, int maxY) {
		this.maxX = maxX;
		this.maxY = maxY;
		cases = new TreeMap<Integer, CaseAbstract>();

	}

	public Cases() {
		cases = new TreeMap<Integer, CaseAbstract>();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see modele.cases.CasesInterface#put(int,
	 * modele.cases.interfaces.CaseInterface)
	 */
	@Override
	public void put(int i, CaseAbstract cas) {
		cases.put(i, cas);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see modele.cases.CasesInterface#getCases()
	 */
	@Override
	public Collection<CaseAbstract> getCases() {
		return cases.values();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see modele.cases.CasesInterface#get(int, int)
	 */
	@Override
	public CaseAbstract get(int i, int j) {
		if (i < 1) {
			i = maxX;
		}
		if (j < 1) {
			j = maxY;
		}
		if (i > maxX) {
			i = 1;
		}
		if (j > maxY) {
			j = 1;
		}
		for (CaseAbstract cas : cases.values()) {
			if (cas.getX() == i && cas.getY() == j) {
				return cas;
			}
		}
		return null;
	}
}
